<div class="layuimini-container layuimini-page-anim" divname="device">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">设备SN</label>
                            <div class="layui-input-inline">
                                <input type="text" maxlength="16" name="DeviceSn" autocomplete="off" class="layui-input">
                                <input type="hidden" name="OldDeviceSn" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">设备名称</label>
                            <div class="layui-input-inline">
                                <input type="text" maxlength="30" name="DeviceName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <!-- <button id="btntest" type="submit" class="layui-btn layui-btn-primary" lay-filter="data-test-btn">
                                <i class="layui-icon"></i> 测试
                            </button>
                            -->
                        </div>
                    </div>
                </form>
            </div>

        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">

                <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="reload"> 刷新 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
                <button class="layui-btn layui-btn-sm demolist" id="opendemolist" data-id="111">开门操作</button>
                <button class="layui-btn layui-btn-sm demolist" id="peopledemolist" data-id="111">人员操作</button>
                <button class="layui-btn layui-btn-sm demolist" id="alarmdemolist" data-id="111">报警操作</button>
                <button class="layui-btn layui-btn-sm demolist" id="devicedemolist" data-id="111">设备操作</button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn layui-hide" lay-event="showDefault"> 出厂默认值 </button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn " lay-event="uploadsoftfile"> 上传固件到服务器 </button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="addDevice"> 添加设备 </button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="searchDevice"> 搜索设备 </button>
            </div>
        </script>

        <table class="layui-hide" id="DevicePageTable" lay-filter="DevicePageTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<style>
    .label_online {
        color: #0034FF;
    }

    .label_offline {
        color: #DC143C;
    }

    .label_alarm {
        margin-left: 5px;
        color: red;
    }


    .status-black {
        margin-left: 10px;
        padding-left: 5px !important;
        padding-right: 5px !important;
        color: black;
    }

    .status-red {
        color: red;
    }

    .status-blue {
        color: blue;
    }

    .status-MediumSeaGreen {
        color: mediumSeaGreen;
    }

    .status-magenta {
        color: magenta;
    }

    .status-Tomato {
        color: tomato;
    }

    .status-darkred {
        color: darkred;
    }
</style>
<script>
    layui.use(['form', 'table', 'miniPage', 'element', 'faceAPI', 'dropdown'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        var faceAPI = layui.faceAPI;
        var tabDatas = null;
        var dropdown = layui.dropdown;





        //$('#btntest').on('click', function () {
        //    var that = this;
        //    layer.tips('只想提示地精准些', that); //在元素的事件回调体中，follow直接赋予this即可
        //});

        table.render({
            elem: '#DevicePageTable',
            //**************************异步请求开始***********************
            url: 'api/FaceDeviceNew/GetDeviceTable',
            method: 'post',
            headers: {
                //token: 'sasasas',
                Authorization: "Bearer " + faceAPI.GetJWTToken()
            },//增加Token验证头
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) { //res 即为原始返回的数据
                //  debugger
                if (res.errCode == 0) {
                    var data = res.content.dataList;
                    var ret = {
                        "code": res.errCode, //解析接口状态
                        "msg": res.error, //解析提示文本
                        "count": data.length, //解析数据长度
                        "data": data //解析数据列表
                    };
                    return ret;

                } else {
                    /*layer.open({
                        title: '请求错误',
                        content: '(' + res.errCode + ')' + res.error
                    });  */

                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": 0, //解析数据长度
                        "data": [] //解析数据列表
                    };
                }

            },
            //**************************异步请求结束***********************

            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { type: "checkbox", width: 50 },
                { field: 'id', width: 80, title: 'ID', sort: true },
                { field: 'deviceID', width: 170, title: 'SN', sort: true },
                { field: 'deviceName', width: 200, title: '名称', sort: true },
                {
                    field: 'deviceName', width: 200, title: 'IP/端口', sort: true,
                    templet: function (d) {
                        var stip;
                        stip = d.deviceIP + ':' + d.devicePort;
                        return stip;
                    }
                },
                {
                    field: 'connectType', width: 120, title: '连接类型',
                    templet: function (d) {
                        if (d.connectType == 0) return '服务器端';
                        return "客户端";
                    }
                },
                { field: 'parameterFirmwareMsg', width: 120, title: '版本号' },
                {//出入类型 0,入门；1，出门
                    field: 'parameterAccessType', width: 110, title: '出入类型',
                    templet: function (d) {
                        if (d.parameterAccessType == 0) return '入门';
                        return "出门";
                    }
                },
                {
                    field: 'parameterKeepOpenDoor', width: 90, title: '开门保持',
                    templet: function (d) {
                        return d.parameterKeepOpenDoor + "秒";
                    }
                },
                {//免验证开门 1--启用；0--禁用
                    field: 'parameterLaissezSwitch', width: 90, title: '免验证',
                    templet: function (d) {
                        if (d.parameterLaissezSwitch == 1) return '启用';
                        return "禁用";
                    }
                },
                {//最近保活时间
                    field: 'lastKeepaliveTime', width: 180, title: '状态', sort: true,
                    templet: function (d) {
                        var stip;
                        stip = '<div LAY_TABLE_INDEX="' + d.LAY_TABLE_INDEX + '" sn="' + d.deviceID + '" name="Onlinestatus">';

                        // stip = stip + getDeviceStatus(d);


                        stip = stip + '</div>';
                        return stip;
                    }
                },
                { title: '操作', width: 120, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [100, 200, 300, 400, 500, 600],
            limit: 100,
            page: true,
            skin: 'line',
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度

                if (res.count > 0) {
                    var iTipIndex = 0;
                    tabDatas = res.data;
                    tipRegEvent();


                }
                else {
                    tabDatas = null;
                }
            }
        });


        var doorStatusTitle = [];//门状态  0--无门磁；1--门开；2--门关
        doorStatusTitle[0] = '<span class="status-magenta">无门磁</span>';
        doorStatusTitle[1] = '<span class="status-Tomato">门开</span>';
        doorStatusTitle[2] = '<span class="status-MediumSeaGreen">门关</span>';

        var alarmStatusTitle = [];//设备报警状态  0--无报警；1--消防报警；2--门磁报警；3--开门超时报警；4--黑名单报警
        alarmStatusTitle[""] = '<span class="status-MediumSeaGreen">无报警</div>';
        alarmStatusTitle["fire"] = '<span class="status-red">消防报警</span>';
        alarmStatusTitle["sensor"] = '<span class="status-red">门磁报警</span>';
        alarmStatusTitle["openTimeout"] = '<span class="status-Tomato">开门超时报警</span>';
        alarmStatusTitle["blacklist"] = '<span class="status-darkred">黑名单报警</span>';
        alarmStatusTitle["illegal"] = '<span class="status-darkred">非法验证报警</span>';
        alarmStatusTitle["password"] = '<span class="status-darkred">胁迫报警密码报警</span>';
        alarmStatusTitle["anti"] = '<span class="status-darkred">防拆报警</span>';

        ///检查是否在线
        function getDeviceStatus(item) {
            //var lastTime = dayjs(item.lastKeepaliveTime, "YYYY-MM-DD HH:mm:ss");
            var onlineTime = dayjs(item.onlineTime, "YYYY-MM-DD HH:mm:ss");
            var second = dayjs().diff(onlineTime, 'second');
            var isOnline = (second < 40);
            var stip = "";
            if (isOnline) {
                stip = '<span class="label label_online">在线</span>';
                if (item.doorSensor > 0) {//门状态  0--无门磁；1--门开；2--门关
                    stip = stip + '<span>' + doorStatusTitle[item.doorSensor] + '</span>';
                }
                if (item.alarm !='') {//设备报警状态  0--无报警；1--消防报警；2--门磁报警；3--开门超时报警；4--黑名单报警
                    stip = stip + '<span class="label label_alarm">' + alarmStatusTitle[item.alarm] + '</span>';
                }
            }
            else
                stip = '<span class="label label_offline">离线</span>';


            return stip;
        }

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = data.field;
            //执行搜索重载
            table.reload('DevicePageTable', {
                page: {
                    curr: 1
                }
                , where: result
            }, 'data');

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(DevicePageTableFilter)', function (obj) {
            if (obj.event === 'showDefault') {   // 监听添加操作

                var openWH = miniPage.getOpenWidthHeight();
                faceAPI.DevicePageDefault = null;

                faceAPI.Ajax({
                    type: 'Get',
                    data: { DeviceIDs },
                    url: '/api/FaceDevice/GetDefaultValue',
                    success: function (result) {
                        if (result.result == false) {
                            layer.alert(result.error, { icon: 2 });
                        }
                        else {
                            //显示弹层
                            faceAPI.DevicePageDefault = result.content;
                            var content = miniPage.getHrefContent('page/Device/default.html');//加载默认参数页面

                            var index = layer.open({
                                title: '设备出厂参数默认值',
                                type: 1,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: [openWH[0] + 'px', openWH[1] + 'px'],
                                offset: [openWH[2] + 'px', openWH[3] + 'px'],
                                content: content
                            });
                            $(window).on("resize", function () {
                                layer.full(index);
                            });
                        }

                    }
                });

            }
            else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('DevicePageTable')
                    , data = checkStatus.data;
                var id = "";
                //console.log(data);
                data.forEach(function (item, index) {
                    id += item.id + ",";
                });
                if (id.length == 0) {

                    layer.alert('请勾选需要删除的设备');
                    return;
                }
                faceAPI.Ajax({
                    type: 'Post',
                    data: { id },
                    url: '/api/FaceDeviceNew/DeleteDevice',
                    success: function (result) {
                        if (result.result == false) {
                            layer.alert(result.error, { icon: 2 });
                        }
                        else {
                            //刷新页面
                            table.reload('DevicePageTable', {
                                page: {
                                    curr: 1
                                }
                            }, 'data');
                        }

                    }
                });
            }
            else if (obj.event === 'reload') {
                table.reload('DevicePageTable', {
                    page: {
                        curr: 1
                    }
                }, 'data');
            }
            else if (obj.event === 'uploadsoftfile') {
                UploadSoftFile();
            } else if (obj.event === 'addDevice') {
                AddDevice();
            } else if (obj.event === 'searchDevice') {
                var openWH = miniPage.getOpenWidthHeight();
                var content = 'page/Device/serachDevice.html';
                var index = layer.open({
                    title: '搜索设备',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['900px', '600px'],
                    //  offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: miniPage.getHrefContent(content),
                    end: function (layero, index) {

                        //var rst = faceAPI.DevicePageUpdateResult;
                        ////console.log(rst);
                        //if (rst != null && rst.result) {
                        //    var device = rst.content;
                        //    //执行搜索重载
                        //    obj.update(device);
                        //};
                    }
                });
            }
        });
        function UploadSoftFile() {
            var openWH = miniPage.getOpenWidthHeight();
            var content = miniPage.getHrefContent('page/Device/uploadsoft.html');

            var index = layer.open({
                title: '上传固件',
                type: 1,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: [openWH[0] + 'px', openWH[1] + 'px'],
                offset: [openWH[2] + 'px', openWH[3] + 'px'],
                content: content
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
        }
        function AddDevice() {
            var openWH = miniPage.getOpenWidthHeight();
            var content = miniPage.getHrefContent('page/Device/addDevice.html');

            var index = layer.open({
                title: '添加设备',
                type: 1,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: "700px",
                content: content,
                end: function (layero, index) {

                    var rst = faceAPI.FaceDeviceAddResult;
                    if (rst != null && rst.result) {
                        table.reload('DevicePageTable', {
                            page: {
                                curr: 1
                            }
                        }, 'data');
                    };

                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
        }
        table.on('sort(DevicePageTableFilter)', function (obj) {
            if (tabDatas == null) return;

            tipRegEvent();

        });

        function tipRegEvent() {
            $("[lay-id=DevicePageTable] [name=Onlinestatus]").mouseenter(Onlinestatus_mouseenter);
            $("[lay-id=DevicePageTable] [name=Onlinestatus]").mouseleave(() => {
                if (iMouseenter_TipIndex > 0)
                    layer.close(iMouseenter_TipIndex);
            });
        }


        // 在线离线状态显示提示框
        var iMouseenter_TipIndex = 0;
        function Onlinestatus_mouseenter() {
            var that = this;
            if (iMouseenter_TipIndex > 0)
                layer.close(iMouseenter_TipIndex);
            var spn = $(that);
            var iItemIndex = spn.attr("LAY_TABLE_INDEX");
            var row = tabDatas[iItemIndex];
            var sHtml = '';

            var lastTime = dayjs(row.lastKeepaliveTime, "YYYY-MM-DD HH:mm:ss");
            var onlineTime = dayjs(row.onlineTime, "YYYY-MM-DD HH:mm:ss");
            //var second = dayjs().diff(onlineTime, 'second');
            sHtml = '<ul><li><span>' + row.deviceID + '</span></li><hr/>';
            var second = dayjs().diff(lastTime, 'second');
            sHtml = sHtml + '<li><span>最近保活时间：' + row.lastKeepaliveTime + '</span></li>';
            sHtml = sHtml + '<li><span>距离现在时间：' + second + '秒</span></li> ';

            second = dayjs().diff(onlineTime, 'second');

            sHtml = sHtml + '<li><span>最近连线时间：' + row.onlineTime + '</span> </li>';
            sHtml = sHtml + '<li><span>距离现在时间：' + second + '秒</span></li> ';



            if (second < 40) {
                sHtml = sHtml + '<li>在线状态：<span class="label label_online">在线</span></li> ';
                //门磁状态
                sHtml = sHtml + '<li><span>门磁：' + doorStatusTitle[row.doorSensor] + '</span></li> ';
                //报警状态
                sHtml = sHtml + '<li><span>报警：' + alarmStatusTitle[row.alarm] + '</span></li> ';
            }
            else {
                sHtml = sHtml + '<li>在线状态：<span class="label label_offline">离线</span></li> ';
            }






            sHtml = sHtml + '</ul>'

            iMouseenter_TipIndex = layer.tips(sHtml, that, { area: ['230px', '230px'] });
        }
        //启动一个定时刷新任务
        var iDeviceIntervalID = setInterval(() => {

            if (faceAPI.DeviceIntervalID != iDeviceIntervalID) {

                clearInterval(iDeviceIntervalID);
                return;
            }
            if ($("[divname=device]").length == 0) {
                clearInterval(iDeviceIntervalID);
                faceAPI.DeviceIntervalID = 0;
                return;
            }

            var SNList = [];
            var hr = new HashTable();
            tabDatas.forEach((value, index, array) => {
                hr.Add(value.deviceID, value);
                SNList.push(value.deviceID);
            });


            faceAPI.Ajax({
                type: 'Post',
                data: { SNList },
                url: '/api/FaceDeviceNew/GetDeviceOnlineStatus',
                success: function (result) {
                    if (result.result == false) {
                        layer.alert(result.error, { icon: 2 });
                    }
                    else {
                        var resultStatus = result.content;
                        resultStatus.forEach((value, index, array) => {
                            var item = hr.GetValue(value.deviceSn);
                            //debugger;
                            item.lastKeepaliveTime = value.lastKeepaliveTime;
                            item.onlineTime = value.onlineTime;
                            item.doorSensor = value.doorSensor;
                            item.alarm = value.alarm;
                            //item.uploadStatus = value.uploadStatus;
                            //item.uploadStatusTime = value.uploadStatusTime;

                            var itemjq = $('[lay-id=DevicePageTable] td [sn=' + item.deviceID + ']');


                            var sHtml = getDeviceStatus(item);
                            itemjq.html(sHtml);

                        });
                        //
                    }

                }
            });
        }, 1000);
           faceAPI.DeviceIntervalID = iDeviceIntervalID;

        table.on('tool(DevicePageTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {

                var content = miniPage.getHrefContent('page/Device/update.html');
                var openWH = miniPage.getOpenWidthHeight();
                faceAPI.DevicePageUpdate = null;//向layer页面传值，传值主要代码
                faceAPI.DevicePageUpdateResult = null;
                faceAPI.Ajax({
                    type: 'Get',
                    url: '/api/FaceDeviceNew/GetDeviceDetail/' + data.deviceID,
                    success: function (result) {
                        if (result.result == false) {
                            layer.alert(result.error, { icon: 2 });
                        }
                        else {
                            //显示弹层
                            faceAPI.DevicePageUpdate = result.content;
                            var index = layer.open({
                                title: '编辑设备参数',
                                type: 1,
                                shade: 0.2,
                                maxmin: true,
                                shadeClose: true,
                                area: [openWH[0] + 'px', openWH[1] + 'px'],
                                offset: [openWH[2] + 'px', openWH[3] + 'px'],
                                content: content,
                                end: function (layero, index) {

                                    var rst = faceAPI.DevicePageUpdateResult;
                                    //console.log(rst);
                                    if (rst != null && rst.result) {
                                        var device = rst.content;


                                        //执行搜索重载
                                        obj.update(device);
                                    };
                                }
                            });
                            $(window).on("resize", function () {
                                layer.full(index);
                            });
                        }

                    }
                });
                return false;
            }
            else if (obj.event === 'delete') {
                layer.confirm('操作确认：删除设备[' + data.deviceID + '(' + data.deviceName + ')]?', function (index) {
                    var id = data.id;
                    //id.push(data.id);
                    faceAPI.Ajax({
                        type: 'Post',
                        data: { id },
                        url: '/api/FaceDeviceNew/DeleteDevice',
                        success: function (result) {
                            if (result.result == false) {
                                layer.alert(result.error, { icon: 2 });
                            }
                            else {
                                //刷新页面
                                obj.del();
                            }

                        }
                    });

                    layer.close(index);
                });
            }
        });


        dropdown.render({
            elem: '#opendemolist'
            , data: [{
                title: '远程开门',
                id: 'SoftOpenRelay'
            },
            {
                title: '远程关门',
                id: 'SoftCloseRelay'
            },
            {
                title: '远程常开',
                id: 'SoftKeepOpenRelay'
            },
            {
                title: '远程锁定',
                id: 'SoftLock'
            },
            {
                title: '远程解除锁定',
                id: 'SoftUnlock'
            }]
            , click: function (menudata, othis) {

                var checkStatus = table.checkStatus('DevicePageTable')
                    , data = checkStatus.data;
                var DeviceIDs = [];

                data.forEach(function (item, index) { DeviceIDs.push(item.deviceID); });
                if (DeviceIDs.length == 0) {

                    layer.alert('请勾选需要操作的设备');
                    return;
                };
                DeviceRemote(DeviceIDs, menudata);
            }
        });

        dropdown.render({
            elem: '#peopledemolist'
            , data: [{
                title: '获取人员',
                id: 'getPeopleByCode'
            }, {
                title: '获取所有人员',
                id: 'getAllPeople'
            }, {
                title: '清空所有人员',
                id: 'emptyPeople'
            }]
            , click: function (menudata, othis) {
                //  debugger
                var checkStatus = table.checkStatus('DevicePageTable')
                    , data = checkStatus.data;
                var DeviceIDs = [];

                data.forEach(function (item, index) { DeviceIDs.push(item.deviceID); });
                if (DeviceIDs.length == 0) {

                    layer.alert('请勾选需要操作的设备');
                    return;
                };
                if (menudata.id == "getPeopleByCode") {
                    if (DeviceIDs.length != 1) {

                        layer.alert('只能勾选一个需要操作的设备');
                        return;
                    };
                    var openWH = miniPage.getOpenWidthHeight();
                    var content = 'page/Device/getPeopleByCode.html';
                    GetDevicePeople(DeviceIDs[0], content);
                    //$(window).on("resize", function () {
                    //    layer.full(index);
                    //});
                }
                if (menudata.id == "getAllPeople") {
                    if (DeviceIDs.length != 1) {

                        layer.alert('只能勾选一个需要操作的设备');
                        return;
                    };
                    var content = 'page/Device/getPeoples.html';
                    GetDevicePeople(DeviceIDs[0], content);
                }
            }
        });

        function GetDevicePeople(DeviceID, content) {
            faceAPI.GetDevicePoeple = {};
            faceAPI.GetDevicePoeple.Code = DeviceID;
            var openWH = miniPage.getOpenWidthHeight();
            var index = layer.open({
                title: '根据编号查询人员',
                type: 1,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: [openWH[0] + 'px', openWH[1] + 'px'],
                offset: [openWH[2] + 'px', openWH[3] + 'px'],
                content: miniPage.getHrefContent(content),
                end: function (layero, index) {

                    //var rst = faceAPI.DevicePageUpdateResult;
                    ////console.log(rst);
                    //if (rst != null && rst.result) {
                    //    var device = rst.content;
                    //    //执行搜索重载
                    //    obj.update(device);
                    //};
                }
            });
        }


        dropdown.render({
            elem: '#alarmdemolist'
            , data: [
                {
                    title: '解除报警',
                    id: 'SoftCloseAlarm'
                },
                {
                    title: '触发消防报警',
                    id: 'SoftFireAlarm'
                }]
            , click: function (menudata, othis) {

                var checkStatus = table.checkStatus('DevicePageTable')
                    , data = checkStatus.data;
                var DeviceIDs = [];

                data.forEach(function (item, index) { DeviceIDs.push(item.deviceID); });
                if (DeviceIDs.length == 0) {

                    layer.alert('请勾选需要操作的设备');
                    return;
                };
                DeviceRemote(DeviceIDs, menudata);
            }
        });

        dropdown.render({
            elem: '#devicedemolist'
            , data: [
                {
                    title: '校准时间',
                    id: 'SetTime'
                },
                {
                    title: '重启设备',
                    id: 'SoftRestart'
                },
                {
                    title: '恢复出厂设置',
                    id: 'SoftInitialize'
                },
                {
                    title: '重新连接服务器',
                    id: 'ReconnectServer'
                },
                {
                    title: '获取设备状态',
                    id: 'GetStatus'
                },
                {
                    title: '重置设备记录',
                    id: 'RereadRecord'
                }]
            , click: function (menudata, othis) {

                var checkStatus = table.checkStatus('DevicePageTable')
                    , data = checkStatus.data;
                var DeviceIDs = [];

                data.forEach(function (item, index) { DeviceIDs.push(item.deviceID); });
                if (DeviceIDs.length == 0) {

                    layer.alert('请勾选需要操作的设备');
                    return;
                };
                DeviceRemote(DeviceIDs, menudata);
            }
        });


        function DeviceRemote(DeviceIDs, menudata) {


            var index = layer.load(2, {
                shade: [0.8, '#130c0e'], //0.1透明度的白色背景
                content: '正在执行[' + menudata.title + "]操作",
                success: function (layero) {
                    layero.find('.layui-layer-content').css({
                        'paddingTop': '80px',
                        'width': '260px',
                        'textAlign': 'center',
                        'backgroundPositionX': 'center',
                        'font-size': '20px',
                        'color': '#ef5b9c'
                    });
                }
            });
            // var index=
            faceAPI.Ajax({
                type: 'Post',
                data: { DeviceIDs, Remote: menudata.id },
                url: '/api/DeviceRemoteNew/Add',
                success: function (result) {
                    if (result.result == false) {
                      
                        layer.alert(result.error, { icon: 2 });
                    } else {
                        var message = "";
                        for (var i = 0; i < result.length; i++) {
                            message += result[i].content + ":执行【" + menudata.title + "】";
                            if (result[i].result == false) {
                                message += "失败</br>";
                            } else {
                                message += "成功</br>";
                            }
                        }
                        layer.open({
                            title: '提示'
                            , content: message
                        });
                    }
                    layer.close(index);
                  
                }
            });
        }
    });



</script>


